package com.weixin.paleituo.adapter;

import android.content.Context;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.weixin.paleituo.R;
import com.weixin.paleituo.base.BaseRecycleAdapter;
import com.weixin.paleituo.bean.HouseListBean;
import com.weixin.paleituo.help.RecycleViewHolder;
import com.weixin.paleituo.util.LogUtils;
import com.weixin.paleituo.util.StringUtils;
import com.weixin.paleituo.util.UIUtils;

import java.util.List;


/**
 * Author yichao
 * Time  2017/12/1 0:38
 * Dest  楼盘列表
 */

public class FloorHomeRecyclerViewAdapter extends BaseRecycleAdapter<HouseListBean> {
    private String TAG="FloorHomeRecyclerViewAdapter";



    private Context mContext;
    private List<HouseListBean> mDataBeans;

    public FloorHomeRecyclerViewAdapter(Context context, List<HouseListBean> dataBeans) {
        super(context, dataBeans, R.layout.layout_item_floor_home);
        mContext = context;
        mDataBeans = dataBeans;
    }





    @Override
    protected void setData(RecycleViewHolder holder, HouseListBean dataBean,final int position) {
        ImageView mIvIconItemFloorHome=holder.getItemView(R.id.iv_icon_item_floor_home);
        TextView mTvNameItemFloorHome=holder.getItemView(R.id.tv_name_item_floor_home);
        TextView mTvPositionItemFloorHome=   holder.getItemView(R.id.tv_position_item_floor_home);
        LinearLayout   mLlTagsItemFloorHome=   holder.getItemView(R.id.ll_tags_item_floor_home);
        TextView mTvMoneyItemFloorHome=holder.getItemView(R.id.tv_money_item_floor_home);
        LinearLayout mLlRootLayoutItemFloorHome=   holder.getItemView(R.id.ll_root_layout_item_floor_home);

        if (mOnItemClickListener != null) {
            mLlRootLayoutItemFloorHome.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onClick(v, position);
                }
            });

            mTvNameItemFloorHome.setText(dataBean.getHouses()+"");
            mTvPositionItemFloorHome.setText(dataBean.getAddress()+"");
            int soldStatus = dataBean.getSoldStatus();

            UIUtils.showPrice(soldStatus,mTvMoneyItemFloorHome,dataBean.getMoney()+"");

          //  mTvMoneyItemFloorHome.setText(dataBean.getMoney()+"");
            mLlTagsItemFloorHome.removeAllViews();
            List<String> tags = dataBean.getTags();
            LogUtils.i(TAG,tags.toString());
            int tagPosition=-1;
            if (tags!=null&& tags.size()!=0){

                for (String tag:tags){
                    if (!StringUtils.isEmpty(tag)){
                        tagPosition++;
                        if (tagPosition<=2){
                            TextView textView=new TextView(mContext);
                            if (tagPosition==0){
                                textView.setTextColor(UIUtils.getColor(R.color.c_ff37f4c5));
                                textView.setBackgroundResource(R.drawable.tag_1_shape);

                            }else if (tagPosition==1){
                                textView.setTextColor(UIUtils.getColor(R.color.c_25a6e9));
                                textView.setBackgroundResource(R.drawable.tag_2_shape);
                                LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                                layoutParams.setMargins(UIUtils.dip2px(15),0,0,0);
                                textView.setLayoutParams(layoutParams);

                            }else if (tagPosition==2){
                                textView.setTextColor(UIUtils.getColor(R.color.c_d84cfb));
                                textView.setBackgroundResource(R.drawable.tag_3_shape);
                                LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                                layoutParams.setMargins(UIUtils.dip2px(15),0,0,0);
                                textView.setLayoutParams(layoutParams);
                            }

                            textView.setPadding(UIUtils.dip2px(5),UIUtils.dip2px(2),UIUtils.dip2px(5),UIUtils.dip2px(2));
                            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,UIUtils.px2dip(UIUtils.getDimens(R.dimen.sp_12)));
                            textView.setGravity(Gravity.CENTER);
                            textView.setText(tag);
                            mLlTagsItemFloorHome.addView(textView);
                        }


                    }
                }
            }

            Glide.with(mContext).load(dataBean.getImgurl()).into(mIvIconItemFloorHome);


            /*  <TextView
            android:layout_marginLeft="@dimen/dp_15"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/c_fffce2c5"
            android:gravity="center"
            android:paddingBottom="@dimen/dp_2"
            android:paddingLeft="@dimen/dp_5"
            android:paddingRight="@dimen/dp_5"
            android:paddingTop="@dimen/dp_2"
            android:text="低密度"
            android:textColor="@color/c_FDA444"
            android:textSize="@dimen/sp_12" />*/

        }
    }


    private OnItemClickListener mOnItemClickListener;

    public interface OnItemClickListener {
        public void onClick(View v, int position);

    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;

    }


}
